package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 查询购物车内商品
     * @param shoppingCart
     * @return
     */
    ShoppingCart getShoppingCart(ShoppingCart shoppingCart);

    /**
     * 更新商品数量
     * @param dbShoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateShoppingCart(ShoppingCart dbShoppingCart);

    /**
     * 添加商品
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart values (null, #{name}, #{image}, #{userId}, #{dishId}," +
            " #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void save(ShoppingCart shoppingCart);

    /**
     * 根据用户id查询购物车
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    /**
     * 删除商品
     * @param ids
     */
    void delete(List<Long> ids);

    /**
     * 查询购物车所有商品
     * @param currentId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> findByUserId(Long userId);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    /**
     * 批量插入
     * @param shoppingCartList
     */
    void saveBatch(List<ShoppingCart> shoppingCartList);
}
